/* portal - form */
const reg = /^(\w){6,20}$/
export const validatePass = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('原密码不能为空！'))
    this.fromFlag = false
  } else if (!reg.test(value)) {
    callback(new Error('请检查密码格式(只能输入6-20个字母、数字、下划线)'))
    this.fromFlag = false
  } else {
    this.fromFlag = true
  }
}
export const validateNewPass = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('请输入新密码！'))
    this.fromFlag = false
  } else if (!reg.test(value)) {
    callback(new Error('请检查密码格式(只能输入6-20个字母、数字、下划线)'))
    this.fromFlag = false
  } else {
    if (this.formCustom.newPasswdCheck !== '') {
      // 对第二个密码框单独验证
      this.$refs.formCustom.validateField('newPasswdCheck')
    }
    this.fromFlag = true
    callback()
  }
}
export const validatePassCheck = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('密码不能为空！'))
    this.fromFlag = false
  } else if (value !== this.formCustom.newpasswd) {
    callback(new Error('两次输入密码不一致！'))
    this.fromFlag = false
  } else if (!reg.test(value)) {
    callback(new Error('请检查密码格式(只能输入6-20个字母、数字、下划线)'))
    this.fromFlag = false
  } else {
    this.fromFlag = true
    callback()
  }
}
/* dic-form */
export const validateDataCode = (rule, value, callback) => {
  const reg = /^[+]{0,1}(\d+)$/
  if (value === '') {
    this.pass = false
    callback(new Error('字典代码不能为空'))
  } else if (!reg.test(value)) {
    this.pass = false
    callback(new Error('请输入正整数'))
  } else {
    this.pass = true
  }
}
export const validateGroupCode = (rule, value, callback) => {
  const reg = /^[5A-Za-z0-9-\_]+$/
  if (value === '') {
    callback(new Error('字典代码不能为空'))
  } else if (!reg.test(value)) {
    this.pass = false
    callback(new Error('只能输入英文字母或下划线'))
  }
}
